/*
 * Created by JFormDesigner on Sat Nov 02 12:07:03 CST 2024
 */

package com.hafu.view;

import com.hafu.model.KuCun;
import com.hafu.service.KuCunService;

import java.awt.*;
import java.util.ArrayList;
import java.util.Vector;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.table.*;

/**
 * @author Asus
 */
public class KuCunFrm extends JFrame {
    private KuCunService KuCunService = new KuCunService();
    public KuCunFrm() {
        initComponents();
        //填充表格数据
        fillTableData();
    }
    private void fillTableData() {
        //获取表格
        DefaultTableModel model = (DefaultTableModel) table1.getModel();
        model.setColumnCount(0);
        //获取数据
        ArrayList<KuCun> List = KuCunService.getKuCunList();
        for (KuCun kuCun : List) {
            Vector<Object> rowData = new Vector<>();
            rowData.add(kuCun.getId());
            rowData.add(kuCun.getSpname());
            rowData.add(kuCun.getNum());
            //添加一行数据
            model.addRow(rowData);
        }
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        scrollPane1 = new JScrollPane();
        table1 = new JTable();

        //======== this ========
        setTitle("\u5e93\u5b58\u8be6\u5355");
        Container contentPane = getContentPane();

        //======== scrollPane1 ========
        {

            //---- table1 ----
            table1.setModel(new DefaultTableModel(
                new Object[][] {
                    {null, null, null},
                    {null, null, null},
                },
                new String[] {
                    "\u7f16\u53f7", "\u540d\u79f0", "\u6570\u91cf"
                }
            ));
            scrollPane1.setViewportView(table1);
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGap(22, 22, 22)
                    .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JScrollPane scrollPane1;
    private JTable table1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
